package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.core.domain.JsonResponse;
import com.ruoyi.system.domain.dto.TTopicDto;
import com.ruoyi.system.domain.po.TTopic;
import com.ruoyi.system.domain.vo.TTopicVo;
import com.ruoyi.system.service.TTopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author nanyang
 */
@RestController
@RequestMapping("/topic")
@Api(tags = "课题管理")
public class TTopicController {

    @Resource
    TTopicService topicService;


    @ApiOperation("新增课题")
    @PostMapping("/insertTopic")
    public JsonResponse insertTopic(@RequestBody @Validated TTopicDto.Insert topicInsert){
        return JsonResponse.ok(topicService.insertTopic(topicInsert));
    }

    @ApiOperation("修改课题")
    @PostMapping("/updateTopic")
    public JsonResponse updateTopic(@RequestBody @Validated TTopicDto.Update topicUpdate){
        return JsonResponse.ok(topicService.updateTopic(topicUpdate));
    }

    @ApiOperation("删除课题")
    @PostMapping("/deleteTopic")
    public JsonResponse deleteTopic(@RequestBody @Validated TTopicDto.Delete topicDelete){
        return JsonResponse.ok(topicService.deleteTopic(topicDelete));
    }

    @ApiOperation("查询课题列表")
    @PostMapping("/listTopic")
    public JsonResponse<PageInfo<TTopicVo>> listTopic(@RequestBody @Validated BaseDto<TTopicDto.Query> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(topicService.listTopic(list.getParam())));
    }

}
